//
//  SCShowLoadingCountView.swift
//  weibo
//
//  Created by 阿城 on 15/12/12.
//  Copyright © 2015年 阿城. All rights reserved.
//

import UIKit

class SCShowLoadingCountView: UIView {

    
    var count: Int = 0{
        didSet{
            if count == 0{
                label.text = "没有数据加载...."
            }else{
                label.text = "加载了\(count)条数据"
            }
            
            //显示
//            self.hidden = false
            UIView.animateWithDuration(0.5, animations: { () -> Void in
                self.alpha = 0.9
                self.transform = CGAffineTransformMakeTranslation(0, self.bounds.height)
                }) { (_) -> Void in
                    //延时
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (Int64)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), { () -> Void in
                        //隐藏
                        UIView.animateWithDuration(0.5, animations: { () -> Void in
                            self.alpha = 0
                            self.transform = CGAffineTransformIdentity
                            }, completion: nil)
                        
                    })
                    
            }
        }
    }
    
    private var label: UILabel = {
        let lab = UILabel(titleText: "", fontSize: 16)
        lab.textAlignment = NSTextAlignment.Center
        return lab
    }()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func setupUI(){
        addSubview(label)
        backgroundColor = UIColor.orangeColor()
        label.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(UIEdgeInsetsZero)
        }
        self.alpha = 0
    }
    
}
